package com.chushouya.order.constants;

import com.general.framework.core.enums.IEnum;

import java.util.Objects;

/**
 * 邮寄订单流程枚举
 * 流程: 0-1-30-32-31-80-90-100
 */
public enum ExpressOrderProcessEnum implements IEnum<Integer> {

    NEW_ORDER(0, "下单成功", "订单提交成功"),
    WAIT_CHECK(1, "待确认", "商家已确认订单"),
    WAIT_DELIVERY(32, "待快递发货", "等待快递发货，发货前请解锁手机并保持电量50%以上"),
    WAIT_RECEIVE(30, "待商家收货", "快递已发货，等待商家收货，确认收货后48小时内商家会完成质检"),
    WAIT_QUALITY(31, "待商家质检", "商家已收货，正在质检中,预计2个工作日完成质检"),
    WAIT_BARGAIN(80, "商家已质检", "商家已质检，预计1个工作日内完成打款"),
    WAIT_PAY(90, "待商家打款", "商家已质检，预计1个工作日内完成打款"),
    COMPLETE(100, "已完成", "订单已完成，感谢您的支持！");

    private Integer value;
    private String desc;
    private String statusText;

    ExpressOrderProcessEnum(Integer value, String desc, String statusText) {
        this.value = value;
        this.desc = desc;
        this.statusText = statusText;
    }

    public static String getDesc(Integer status) {
        for (ExpressOrderProcessEnum thisEnum : ExpressOrderProcessEnum.values()) {
            if (Objects.equals(thisEnum.value, status)) {
                return thisEnum.desc;
            }
        }
        return ExpressOrderProcessEnum.NEW_ORDER.desc;
    }

    public static ExpressOrderProcessEnum get(Integer status) {
        for (ExpressOrderProcessEnum thisEnum : ExpressOrderProcessEnum.values()) {
            if (Objects.equals(thisEnum.value, status)) {
                return thisEnum;
            }
        }
        return ExpressOrderProcessEnum.NEW_ORDER;
    }

    /**
     * 获取下一个状态
     */
    public ExpressOrderProcessEnum getNext() {
        switch (this) {
            case NEW_ORDER:
                return WAIT_CHECK;
            case WAIT_CHECK:
                return WAIT_RECEIVE;
            case WAIT_RECEIVE:
                return WAIT_DELIVERY;
            case WAIT_DELIVERY:
                return WAIT_QUALITY;
            case WAIT_QUALITY:
                return WAIT_BARGAIN;
            case WAIT_BARGAIN:
                return WAIT_PAY;
            case WAIT_PAY:
                return COMPLETE;
            default:
                return this;
        }
    }

    @Override
    public Integer value() {
        return this.value;
    }

    @Override
    public String named() {
        return this.desc;
    }

    public String getDesc() {
        return desc;
    }

    public String getStatusText() {
        return statusText;
    }
}
